<?php

namespace App\Admin\Controllers;

use App\Models\ProductModel;
use App\Models\ProductNameModel;
use Encore\Admin\Controllers\AuthController as BaseAuthController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ApiController extends BaseAuthController
{
    public function varietyName(Request $request)
    {
        $pid = $request->get('q');
        return ProductNameModel::where('id', $pid)->get(['id', DB::raw('variety_name as text')]);
    }

    public function productNameAjax(Request $request)
    {
        $q = $request->get('q');

        return ProductNameModel::where('name', 'like', "%$q%")->paginate(null, ['id', 'name as text']);
    }

    public function productAjax(Request $request)
    {
        $q = $request->get('q');

        return ProductModel::where('product_name', 'like', "%$q%")->paginate(null, ['product_id', 'product_name as text']);
    }
}
